package com.qsw.paper.controller.admin;


import com.qsw.paper.constant.MessageConstants;
import com.qsw.paper.pojo.dto.AdvisorsDto;
import com.qsw.paper.pojo.dto.AdvisorsQueryDto;
import com.qsw.paper.result.PageResult;
import com.qsw.paper.result.Result;
import com.qsw.paper.service.IAdvisorsService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author qsw
 * @since 2024-11-15
 */
@RestController("adminAdvisorsController")
@RequestMapping("/admin/advisor")
@RequiredArgsConstructor
@Slf4j
public class AdvisorsController {
    private final IAdvisorsService advisorsService;


    /**
     * 分页查询
     *
     * @param queryDto dto
     * @return 分页列表
     */
    @GetMapping("/list")
    public Result<PageResult<?>> pageList(AdvisorsQueryDto queryDto) {
        log.info("管理员分页查询:{}", queryDto);
        return Result.success(advisorsService.pageList(queryDto), MessageConstants.SELECT_OK);
    }


    /**
     * 添加导师
     *
     * @param advisorsDto dto
     * @return 提示
     */
    @PostMapping("/add")
    public Result<?> save(@RequestBody @Validated AdvisorsDto advisorsDto) {
        log.info("管理员添加导师：{}", advisorsDto);
        advisorsService.save(advisorsDto);
        return Result.success(MessageConstants.ADD_OK);
    }

    /**
     * 修改导师信息
     *
     * @param advisorsDto dto
     * @param id          导师id
     * @return 提示
     */
    @PutMapping("/update/{id}")
    public Result<?> update(@RequestBody AdvisorsDto advisorsDto, @PathVariable Integer id) {
        log.info("管理员修改导师信息:{},{}", advisorsDto, id);
        advisorsService.update(advisorsDto, id);
        return Result.success(MessageConstants.OPERATION_SUCCESSFUL);
    }


    /**
     * 删除导师信息
     *
     * @param id 导师id
     * @return 提示
     */
    @DeleteMapping("/delete/{id}")
    public Result<?> delete(@PathVariable Integer id) {
        log.info("管理员删除导师信息:{}", id);
        advisorsService.delete(id);
        return Result.success(MessageConstants.OPERATION_SUCCESSFUL);
    }


    /**
     * 获取导师详细信息
     *
     * @param id 导师id
     * @return 导师实体
     */
    @GetMapping("/{id}")
    public Result<?> getDetailById(@PathVariable Integer id) {
        log.info("管理员查询导师详细信息:{}", id);
        return Result.success(advisorsService.findById(id), MessageConstants.SELECT_OK);
    }


}
